<?php

namespace app\forms\field;

use app\forms\Model;
use app\models\Field;
use app\helpers\MappingHelper;

/**
 * 字段 父类表单
 */
class BaseForm extends Model
{
    public $module;
    public $type;
    public $formType;
    public $name;
    public $maxLength;
    public $defaultValue;
    public $value;
    public $tips;
    public $isValidate;
    public $isUnique;
    public $isCheck;
    public $isAllowEmpty;
    public $inListShow;
    public $inAddShow;
    public $status;
    public $sort;
    public $auth;

    public function rules()
    {
        return [

            ['name', 'trim'],
            ['name', 'string', 'max' => 32],
            ['name', 'required'],

            ['defaultValue', 'trim'],
            ['defaultValue', 'string', 'max' => 32],
            ['defaultValue', 'default', 'value' => ''],

            ['maxLength', 'integer'],
            ['maxLength', 'default', 'value' => 0],

            ['value', 'trim'],
            ['value', 'string', 'max' => 64],
            ['value', 'default', 'value' => ''],

            ['tips', 'trim'],
            ['tips', 'string', 'max' => 32],
            ['tips', 'default', 'value' => ''],

            ['module', 'integer'],
            ['module', 'required'],
            ['module', 'in', 'range' => array_keys(Field::getModuleMapping())],

            ['type', 'integer'],
            ['type', 'required'],
            ['type', 'in', 'range' => array_keys(Field::getTypeMapping())],

            ['formType', 'integer'],
            ['formType', 'required'],
            ['formType', 'in', 'range' => array_keys(Field::getFormTypeMapping())],

            ['isValidate', 'integer'],
            ['isValidate', 'required'],
            ['isValidate', 'in', 'range' => array_keys(Field::getValidateMapping())],

            ['isUnique', 'integer'],
            ['isUnique', 'required'],
            ['isUnique', 'in', 'range' => array_keys(Field::getUniqueMapping())],

            ['isCheck', 'integer'],
            ['isCheck', 'required'],
            ['isCheck', 'in', 'range' => array_keys(Field::getCheckMapping())],

            ['isAllowEmpty', 'integer'],
            ['isAllowEmpty', 'required'],
            ['isAllowEmpty', 'in', 'range' => array_keys(Field::getAllowEmptyMapping())],

            ['inListShow', 'integer'],
            ['inListShow', 'required'],
            ['inListShow', 'in', 'range' => array_keys(Field::getListShowMapping())],

            ['inAddShow', 'integer'],
            ['inAddShow', 'required'],
            ['inAddShow', 'in', 'range' => array_keys(Field::getAddShowMapping())],

            ['status', 'integer'],
            ['status', 'default', 'value' => MappingHelper::STATUS_ACTIVE],

            ['auth', 'integer'],
            ['auth', 'default', 'value' => Field::AUTH_READ_AND_WRITE],

            ['sort', 'integer'],
            ['sort', 'default', 'value' => 0],
        ];
    }
}